﻿using AppEszköz.ErrorControl.Writers;
using System;
namespace AppEszköz.ErrorControl
{
    public sealed class ErrorHandler
    {
        private ErrorHandler()
        {
        }

        public static void RecordError(Exception ex)
        {
            ErrorHandler.RecordError(new ErrorEntry(ex));
        }

        public static void RecordError(ErrorEntry error)
        {
            if (error == null)
                throw new ArgumentNullException("error");
            Type type = Type.GetType("AppTools.ErrorControl.Writers." + ErrorSettings.Writer, false, true);
            if (type == null)
                throw new MissingMemberException("Invalid ErrorWriter specified in configuration");
            ErrorWriter errorWriter = (ErrorWriter)Activator.CreateInstance(type);
            if (errorWriter == null)
                return;
            errorWriter.Write(error);
        }
    }
}
